<script type="text/javascript">
	
	
function MergeSort(arr) {
	if(arr.length < 1) return [];
	if(arr.length == 1) return arr;

	let mid = arr.length >> 1;
	let leftArr = arr.slice(0, mid),
		rightArr = arr.slice(mid);

	return MergeCore(MergeSort(leftArr), MergeSort(rightArr));
}

function MergeCore(arr1, arr2) {
	let p1 = 0,
		p2 = 0;
	let resArr = [];
	while(p1 < arr1.length && p2 < arr2.length ) {
		if(arr1[p1] <= arr2[p2]) {
			resArr.push(arr1[p1++]);
		} else {
			resArr.push(arr2[p2++]);
		}
	}

	if(p1 == arr1.length) {
		for(let i = p2; i < arr2.length; i++) {
			resArr.push(arr2[i]);
		}
	} else {
		for(let i = p1; i < arr1.length; i++) {
			resArr.push(arr1[i]);
		}
	}

	return resArr;
}

const res = MergeSort([1,6,4,5,2,5,7])
console.log(res)

</script>